﻿using System;

namespace Graphe.Collations
{
    public static class EVariantTypeConverter
    {
        public static EVariantType ToEnum(string stringValue)
        {
            EVariantType type = EVariantType.NotSpecified;

            if (String.IsNullOrEmpty(stringValue))
                return type;

            switch(stringValue.ToLower())
            {
                case "omission":
                    type = EVariantType.Omission;
                    break;
                case "addition":
                    type = EVariantType.Addition;
                    break;
                case "substitution":
                    type = EVariantType.Substitution;
                    break;
                case "incipit":
                    type = EVariantType.Incipit;
                    break;
                case "itacism":
                    type = EVariantType.Itacism;
                    break;
                case "reordering":
                    type = EVariantType.Reordering;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(stringValue, String.Format("The value '{0}' could not be converted to type EVariantType. Another must be specified.", stringValue));
            }

            return type;
        }

        public static string ToString(EVariantType enumValue)
        {
            string type = null;

            switch (enumValue)
            {
                case EVariantType.Addition:
                    type = "addition";
                    break;
                case EVariantType.Incipit:
                    type = "incipit";
                    break;
                case EVariantType.Itacism:
                    type = "itacism";
                    break;
                case EVariantType.Omission:
                    type = "omission";
                    break;
                case EVariantType.Reordering:
                    type = "reordering";
                    break;
                case EVariantType.Substitution:
                    type = "substitution";
                    break;
                default:
                    throw new Exception("The enumeration value passed in was not covered in this conversion class.");
            }

            return type;
        }
    }
}
